package com.tangsm.spring.boot.event.publisher.listener.listener;

import com.tangsm.spring.boot.event.publisher.listener.event.UserRegisterEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 事件监听者
 *
 * <p>通过实现ApplicationListener接口注册事件监听者</p>
 *
 * @author tangsm
 */
@Component
public class UserRegisterEventListener implements ApplicationListener<UserRegisterEvent> {
    private static final Logger log = LoggerFactory.getLogger(UserRegisterEventListener.class);

    /**
     * 注册处理应用程序事件（事件监听者）
     *
     * @param event the event to respond to
     */
    @Override
    public void onApplicationEvent(UserRegisterEvent event) {
        log.info("事件发布者：{}", event.getSource().toString());
        //发邮件
        log.info("UserRegisterEventListener，正在发送邮件至：{}", event.getUser().getEmail());
        //发短信
        log.info("UserRegisterEventListener，正在发短信到：{}", event.getUser().getPhoneNum());
    }
}
